package com.beardedcoder.lowPower.model;

import android.content.Intent;
import android.os.BatteryManager;

/**
 * Class that creates BatteryData domain object from a BatteryIntent.
 * @author bilbovb
 *
 */
public class BatteryDataFactory
{
	/**
	 * Build a BatteryData object from a battery intent.
	 * @param batteryIntent
	 * @return
	 */
	public static BatteryData build(Intent batteryIntent)
	{
		int health = batteryIntent.getIntExtra(BatteryManager.EXTRA_HEALTH, 0);
		int powerSource = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
		int status = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS, 0);
		int powerLevel = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
		int voltage = batteryIntent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0);
		float temperature = batteryIntent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0) / 10.f;
		String technology = batteryIntent.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY);
		int charging = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
		
		return new BatteryData(health, powerSource, status, powerLevel, voltage, temperature, technology, charging);
	}
}
